{% extends 'admin/base.html' %}
{% import "admin/_macros.html" as macros %}

{% block title %}
    Blog_mini -分类导航
{% endblock %}

{% block admin_content %}
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">分类导航</h3>
                </div>
                <div class="panel-body">
                    <div class="entry-box manage-articleTypes-nav">
                        <p><span class="glyphicon glyphicon-bookmark"></span>导航总数：<span
                                class="badge">{{ Menu.query.count() }}</span></p>
                        <div class="articleTypes-nav-box">
                            <ul class="nav nav-tabs">
                                <li class=""><a href="{{ url_for('admin.manage_articleTypes') }}">博文分类</a></li>
                                <li class="active"><a href="{{ url_for('admin.manage_articleTypes_nav') }}">分类导航</a>
                                </li>
                            </ul>
                            <div class="articleTypes-nav" id="articleTypesNav">
                                <table class="table table-striped table-hover">
                                    <thead>
                                    <tr class="table-header">
                                        <th>序号</th>
                                        <th>导航名称</th>
                                        <th>所含分类</th>
                                        <th>排序</th>
                                        <th>修改</th>
                                        <th>删除</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for menu in menus %}
                                        <tr>
                                            <td>{{ menu.order }}</td>
                                            <td>{{ menu.name }}</td>
                                            <td>
                                                {% if menu.types.count() %}
                                                    {% for aritcleType in menu.types.all() %}
                                                        <a href="{{ url_for('main.articleTypes', id=aritcleType.id) }}"
                                                           target="_blank">
                                                            {{ aritcleType.name }}
                                                        </a>
                                                    {% endfor %}
                                                {% else %}
                                                    没有分类，该导航将不显示。
                                                {% endif %}
                                            </td>
                                            <td>
                                                <a class="btn sort-up" title="升序"
                                                   href="{{ url_for('admin.nav_sort_up', id=menu.id, page=page) }}">
                                                    <span class="glyphicon glyphicon-circle-arrow-up"></span>
                                                </a>
                                                <a class="btn sort-down" title="降序"
                                                   href="{{ url_for('admin.nav_sort_down', id=menu.id, page=page) }}">
                                                    <span class="glyphicon glyphicon-circle-arrow-down"></span>
                                                </a>
                                            </td>
                                            <td>
                                                <a class="btn" title="修改导航信息"
                                                   onclick="get_articleTypeNav_info('{{ url_for('admin.get_articleTypeNav_info', id=menu.id) }}')">
                                                    <span class="glyphicon glyphicon-edit"></span>
                                                </a>
                                            </td>
                                            <td>
                                                <a class="btn btn-sm btn-default delete-articleType-nav" title="删除导航"
                                                   onclick="delArticleTypeNavCfm('{{ url_for('admin.delete_nav', id=menu.id, page=page) }}')">
                                                    <span class="glyphicon glyphicon-trash"></span>
                                                </a>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <div class="add-articleType-nav">
                                <a class="btn btn-sm btn-primary add-articleType-nav-btn">
                                    <span class="glyphicon glyphicon-plus-sign"></span>
                                    添加导航
                                </a>
                            </div>
                        </div>
                        <div class="pagination">
                            {{ macros.pagination_widget(pagination, endpoint) }}
                        </div>
                    </div>

                    <!-- 信息删除确认: For add articleTypeNav form-->
                    <div class="modal fade" id="addArticleTypeNavFormModel">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title">添加分类导航</h4>
                                </div>
                                <form id="addArticleTypeNavForm" method="post"
                                      action="{{ url_for('admin.manage_articleTypes_nav', page=page) }}">
                                    <div class="modal-body">
                                        <div class="form-group">
                                            {{ form.csrf_token }}
                                            {{ form.name.label }}
                                            {{ form.name(class='form-control', required='') }}
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                        <button id="addArticleTypeNavCfmClick" type="submit" class="btn btn-success">
                                            确定
                                        </button>
                                    </div>
                                </form>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <!-- 信息删除确认: For edit articleType nav form-->
                    <div class="modal fade" id="editArticleTypeNavFormModel">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title" id="NavModalTitle"></h4>
                                </div>
                                <form id="editArticleTypeNavForm" method="post"
                                      action="{{ url_for('admin.edit_nav', page=page) }}">
                                    <div class="modal-body">
                                        <div class="form-group">
                                            {{ form2.csrf_token }}
                                            {{ form2.nav_id(type='hidden') }}
                                            {{ form2.name.label }}
                                            {{ form2.name(id='editNavName', class='form-control', required='') }}
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                        <button id="editArticleTypeNavCfmClick" type="submit" class="btn btn-success">
                                            确定
                                        </button>
                                    </div>
                                </form>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <!-- 信息删除确认: For delete an nav confirm -->
                    <div class="modal fade" id="delArticleTypeNavCfmModel">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title">确认删除导航？</h4>
                                </div>
                                <div class="modal-body">
                                    <p>
                                        将该导航删除后不可恢复，同时会将该导航的所有分类的导航设置为<strong>无</strong>，您确认要删除吗？
                                    </p>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <a onclick="" id="delArticleTypeNavCfmClick" class="btn btn-success"
                                       data-dismiss="modal">确定</a>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->
                </div>
            </div>
        </div>
    </div>

{% endblock %}